<template>
  <div class="detail-wrapper">
    <el-page-header @back="goBack" content="BOM详情"> </el-page-header>
    <!-- <el-divider></el-divider> -->
    <div class="topBox paddingBorder">
      <el-descriptions
        class="margin-top"
        :title="`${dataForm.name}  ${dataForm.versions}`"
        :column="3"
        :labelStyle="labelStyle"
        :contentStyle="contentStyle"
        border
      >
        <template slot="extra">
          <el-button type="primary" size="small" @click="toEdit"
            >编辑</el-button
          >
          <el-button type="primary" size="small" @click="handleDelete"
            >删除</el-button
          >
        </template>
        <el-descriptions-item>
          <template slot="label"> 创建人 </template>
          {{ dataForm.add_user_name }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label"> 创建时间 </template>
          {{ dataForm.add_time }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label"> 最后修改人 </template>
          {{ dataForm.operator_user }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label"> 修改时间 </template>
          {{ dataForm.operator_time }}
        </el-descriptions-item>
      </el-descriptions>
    </div>

    <div class="top36 prodBox paddingBorder">
      <div class="titleLabel">BOM信息</div>
      <el-descriptions
        class="margin-top top36"
        title="基本信息"
        :column="3"
        :labelStyle="labelStyle"
        :contentStyle="contentStyle"
        border
      >
        <el-descriptions-item>
          <template slot="label"> BOM编号 </template>
          {{ dataForm.bom_serial }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label"> BOM名称 </template>
          {{ dataForm.name }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label"> 版本 </template>
          {{ dataForm.versions }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label"> 产品分类 </template>
          {{ dataForm.classify_name }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label"> 产品名称 </template>
          {{ dataForm.product_id }}
        </el-descriptions-item>
        <el-descriptions-item :span="3">
          <template slot="label"> 备注 </template>
          {{ dataForm.remarks }}
        </el-descriptions-item>
      </el-descriptions>
      <div class="descMockBox">
        <div class="descMockLabel">BOM配件</div>
        <el-table
          :data="dataForm.bom_sub"
          border
          style="width: 100%; margin-top: 20px"
        >
          <el-table-column
            type="index"
            label="序号"
            header-align="center"
            align="center"
            width="80"
          ></el-table-column>
          <el-table-column
            prop="material_serial"
            label="物料编号"
            header-align="center"
            align="center"
          >
          </el-table-column>
          <el-table-column
            prop="name"
            label="物料名称"
            header-align="center"
            align="center"
          >
          </el-table-column>
          <el-table-column
            prop="specifications_model"
            label="规格"
            header-align="center"
            align="center"
          >
          </el-table-column>
          <el-table-column
            prop="parts_num"
            label="配件数量"
            header-align="center"
            align="center"
          >
          </el-table-column>
          <el-table-column
            prop="price"
            label="价格（人民币）"
            header-align="center"
            align="center"
          >
          </el-table-column>
          <el-table-column
            prop="day"
            label="预期工期（天）"
            header-align="center"
            align="center"
          >
          </el-table-column>
          <el-table-column
            prop="daily_output"
            label="日产量（个）"
            header-align="center"
            align="center"
          >
          </el-table-column>
        </el-table>
      </div>
    </div>
  </div>
</template>

<script>
import debounce from 'lodash/debounce'
import { isEmail, isMobile } from '@/utils/validate'
import { addDynamicRoute } from '@/router'
import { getBomDetail, deleteBom } from '@/api'
export default {
  data() {
    return {
      dataForm: {
        name: '',
        versions: '',
      },
      labelStyle: {
        width: '150px',
      },
      contentStyle: {
        width: '28vw',
      },
    }
  },
  computed: {},
  activated() {
    const id = this.$route.params.id
    this.dataForm.id = id
    if (id) this.fetchDetail(id)
  },
  methods: {
    async handleDelete() {
      this.$confirm('此操作将删除该条数据, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(async () => {
          const res = await deleteBom({ id: this.dataForm.id })
          if (res?.status === 1) {
            this.$message.success(res?.msg || '')
            this.$router.go(-1)
          }
        })
        .catch(() => {})
    },
    async fetchDetail(id) {
      const params = {
        id,
      }
      const res = await getBomDetail(params)
      console.log(res)
      if (res?.status === 1) {
        const data = res?.data || {}
        this.dataForm = data
        console.log(data)
      }
    },
    goBack() {
      this.$router.go(-1)
    },
    toEdit() {
      const routeParams = {
        routeName: `product-bom__add`,
        title: `BOM管理 - 编辑`,
        path: 'product/bom-add',
        params: {
          id: this.dataForm.id || '',
        },
      }
      addDynamicRoute(routeParams, this.$router)
    },
  },
}
</script>

<style lang="scss" scoped>
.detail-wrapper {
  background: #fff;
  padding: 20px;
  ::v-deep .el-page-header__title,
  .el-page-header__content {
    font-size: 12px;
  }

  ::v-deep .el-page-header__content {
    font-size: 12px;
  }

  // ::v-deep .el-descriptions__title {
  //   position: relative;
  //   padding-left: 16px;
  //   &::before {
  //     background: $mainColor;
  //     content: '';
  //     display: inline-block;
  //     height: 19px;
  //     left: 0;
  //     position: absolute;
  //     top: calc(50% - 10px);
  //     width: 3px;
  //   }
  // }

  .topBox {
    margin-top: 36px;
    ::v-deep .el-descriptions__title {
      font-size: 20px;
      font-weight: 600;
      position: relative;
      padding-left: 16px;
      color: #303133;
      &::before {
        background: $mainColor;
        content: '';
        display: inline-block;
        height: 20px;
        left: 0;
        position: absolute;
        top: calc(50% - 10px);
        width: 3px;
      }
    }
  }

  .prodBox {
    .prodImgBox {
      .imgItem {
        width: 64px;
        height: 64px;
        margin-left: 12px;
        cursor: pointer;
        &:first-child {
          margin-left: 0;
        }
        img {
          width: 100%;
          height: 100%;
        }
      }
    }
  }
}
</style>

<style lang="scss">
::v-deep .el-page-header__title {
  font-size: 12px;
}
</style>
